Page({
  data: {
    list: [],
    oder: "",
    value: "",
    openidH5: ""
  },
  bindInput(e) {
    //   let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
    //     "alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode="
    //   ) +
    //   encodeURIComponent(encodeURIComponent('https://www.baidu.com'))
    // my.ap.navigateToAlipayPage({
    //   path: link
    // })
    this.setData({
      value: e.detail.value
    })
  },
  change() {
    var that = this
    let params = {
      mobile: that.data.value,
      type: '1',
      ordertype: '15',
      user_id: that.data.openidH5,
      a: '666666',
      buyType: '18',
      pType: '1'
    }
    my.httpRequest({
      url: 'https://www.sx2b2c.com/api/rf/hjkCreatePayNew',
      data: params,
      method: "POST",
      headers: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(result) {
        console.log(result)
        that.setData({
          oder: result.data.data.trade_no
        });
        console.log(that.data.oder)
        my.tradePay({
          // 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号 trade_no
          tradeNO: that.data.oder,
          success: res => {
            my.alert({
              content: JSON.stringify(res),
            });
          },
          fail: error => {
            console.error('调用 my.tradePay 失败: ', JSON.stringify(error));
          },
        });

      },
      fail: function (xhr, type, status) {}
    })


  },
  onLoad(query) {
    const appIdRes = my.getParentAppIdSync();
console.log(appIdRes.appId);
    console.log(query)
    var that = this
    // 页面加载
    my.getAuthCode({
      scopes: ['auth_user'],
      // 主动授权：auth_user，静默授权：auth_base或者其它scope。如需同时获取用户多项授权，可在 scopes 中传入多个 scope 值。
      success: (res) => {
        console.log(res)
        if (res.authCode) {

          let params = {
            code: res.authCode,
            type: 2,
            appid:my.getParentAppIdSync().appId,
          }
          my.httpRequest({
            url: 'https://www.sx2b2c.com/api/hfmp/wxLogincj',
            data: params,
            method: "POST",
            headers: {
              'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            success: function (rex) {
              console.log(rex)
             if(rex.data.code==1){
              if(rex.data.data.openidH5.length<17){
                that.setData({
                  openidH5: rex.data.data.openidH5
                });
              }else{
                let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
                  "alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode="
                ) +
                encodeURIComponent(encodeURIComponent('http://ng.zzqz000.com/lijianjin/#/?a=666666'))
              my.ap.navigateToAlipayPage({
                path: link
              })
              }
             }else{
              let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
                "alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode="
              ) +
              encodeURIComponent(encodeURIComponent('http://ng.zzqz000.com/lijianjin/#/?a=666666'))
            my.ap.navigateToAlipayPage({
              path: link
            })
             }
            
            

            },
            fail: function (xhr, type, status) {}
          })
        }
      },
    });


  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息

  },
});